import Vue from 'vue'
import Vonic from 'vonic'

// Page Components
import Index from './components/Index.vue'
import About from './components/About.vue'
import Login from './components/Login.vue'
import User from './components/indextabbar/User.vue'
import Discount from './components/indextabbar/Discount.vue'
import Home from './components/indextabbar/Home.vue'
import Car from './components/indextabbar/Car.vue'

// Routes
const routes = [
  { path: '/', redirect: "/tabbar/home" },
  { path: '/Login', component: Login },
  { path: '/index', redirect: "/tabbar/home" },
  { path: '/about', component: About },
  {
    path: '/tabbar',
    component: Index,
    children: [
      { path: 'home', component: Home },
      { path: 'discount', component: Discount },
      { path: 'cart', component: Car },
      { path: 'user', component: User }
    ]
  }
]
Vonic.app.setConfig("beforeEach",function(to, from, next){
  if(to.path == "/Login"){
    next();
  }else{
    if(!!sessionStorage.username){
      next();
    }else{
      next("/Login");
    }
  }
 });
Vue.use(Vonic.app, {
  routes: routes
})

